package opn.srn.command.load.parser;

import opn.srn.common.Factory;

public class ParserFactory extends Factory<String, String, IParser> {

	private static ParserFactory instance = new ParserFactory();

	public static ParserFactory get() {
		return instance;
	}

	@SuppressWarnings("unchecked")
	@Override
	public IParser newInstance(String key) throws Exception {
		String className = factory.get(key);
		if (className == null) {
			throw new Exception("Parser by name " + key + " not registered...");
		}

		Class<IParser> parserClass = (Class<IParser>) Class.forName(className);
		return parserClass.newInstance();
	}
}
